package zhao.tx.eecs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import zhao.tx.eecs.R;
import zhao.tx.eecs.dialog.MoreDialog.IInformationClieckListener;

/**
 * Created by ishishuji on 14-3-10.
 */
public class DialogAdapter extends MyAdapter {


    private IInformationClieckListener listener = null;

    public DialogAdapter ( Context context, List<?> data ) {
        super ( context, data, R.layout.dialog_list_item );
    }

    static class ViewHolder {

        private TextView content;

        public ViewHolder ( View v ) {

            content = (TextView) v.findViewById ( R.id.title );

        }

    }

    public void setOnInformationClieckListener ( IInformationClieckListener listener ) {
        this.listener = listener;
    }

    @Override
    public View getView ( int i, View view, ViewGroup viewGroup ) {
        View currentView = null;
        final int location = i;
        ViewHolder holder = null;
        if (view == null || view.getTag() == null) {
            currentView = mLayoutInflater.inflate(layout,null);
            holder = new ViewHolder(currentView);
            currentView.setTag(holder);
        } else {
            currentView = view;
            holder = (ViewHolder) view.getTag();
        }
        if ( data.get ( location ) instanceof String ) {

            String title = ( String ) data.get ( location );

//            holder.author.setText ( information.getReference () );

            holder.content.setText ( title );

            currentView.setOnClickListener ( new View.OnClickListener () {
                @Override
                public void onClick ( View view ) {
                    if ( listener != null ) {
                        listener.onClieck ( view, location);
                    }
                }
            } );

        }


        return currentView;
    }
}
